// 接口函数
import request from '@/utils/request'
// 封装一个获取分类列表的接口函数 测试request模块

// 获取分类列表
export function fetchChannels () {
  return request({
    url: '/v1_0/channels',
    method: 'GET'
  })
}

// 要求调用这个fetchLogin的时候必须传入一个对象
// 并且对象里面必须包含俩个key {mobile:'132xxxx', code:'246810'}
export function fetchLogin ({ mobile, code }) {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 文章 - 获取列表
export const articlesListAPI = ({ channelId, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}

// 文章- 获取详情

export const articleDetailAPI = (id) => {
  return request({
    url: `/v1_0/articles/${id}`,
    method: 'GET'
  })
}

// 文章 - 关注作者

export const followAutAPI = (target) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target
    }
  })
}

// 文章 - 取消关注
export const unFollowAutAPI = (target) => {
  return request({
    url: `/v1_0/user/followings/${target}`,
    method: 'DELETE'
  })
}

// 点赞
export const like = (target) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target
    }
  })
}

// 取消点赞
export const unLike = (target) => {
  return request({
    url: `/v1_0/article/likings/${target}`,
    method: 'DELETE'
  })
}

// 获取用户信息

export const getUser = () => {
  return request({
    url: '/v1_0/user',
    method: 'GET'
  })
}

// 获取用户简介信息

export const getProfile = () => {
  return request({
    url: '/v1_0/user/profile',
    method: 'GET'
  })
}

// 上传头像

export const updatePhoto = (data) => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data
  })
}

// 更新名称

export const updateProfile = ({ name, birthday }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      name,
      birthday
    }
  })
}

// 获取联想建议列表
export const getSuggestListAPI = (q) => {
  return request({
    url: '/v1_0/suggestion',
    method: 'GET',
    params: {
      q
    }
  })
}

export const getSearchResultAPI = ({ page = 1, perPage = 10, q }) => {
  return request({
    url: '/v1_0/search',
    method: 'GET',
    params: {
      page,
      per_page: perPage,
      q
    }
  })
}
